package com.sskj.market.http;


import android.util.Log;

import com.afollestad.materialdialogs.MaterialDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.LanguageUtil;
import com.sskj.lib.bean.PageBean;
import com.sskj.market.bean.AddressBean;
import com.sskj.market.bean.CreateOrderBean;
import com.sskj.market.bean.DefaultAddressBean;
import com.sskj.market.bean.GoodCategoryBean;
import com.sskj.market.bean.HotShoppingDataBean;
import com.sskj.market.bean.MyAddressBean;
import com.sskj.market.bean.OrderDetailsBean;
import com.sskj.market.bean.OrderListBean;
import com.sskj.market.bean.ServicesBean;
import com.sskj.market.bean.ShopDetailsBean;
import com.sskj.market.bean.ShopSearchBean;
import com.sskj.market.bean.ShoppingTitleBean;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService {

    //获取热门商品
    public GetRequest<HttpData<HotShoppingDataBean>> getHotShoppingData(int page) {
        return OkGo.<HttpData<HotShoppingDataBean>>get(HttpConfig.BASE_URL + HttpConfig.MARKET_GET_HOT_SHOPPING_DATA)
                .params("page",page);
    }

    //获取分类轮播图
    public GetRequest<HttpData<ShoppingTitleBean>> getBannerData() {
        return OkGo.<HttpData<ShoppingTitleBean>>get(HttpConfig.BASE_URL + HttpConfig.MARKET_GET_SHOP_BANNER_DATA);
    }

    //添加地址
    public PostRequest<HttpData> addAddress(String name, String phone, String province, String city, String region, String detail, String is_default) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.MARKET_ADD_ADDRESS)
                .params("name", name)
                .params("phone", phone)
                .params("province", province)
                .params("city", city)
                .params("country", region)
                .params("detail", detail)
                .params("is_default", is_default);
    }

    //获取地址
    public GetRequest<HttpData<MyAddressBean>> getMyAddress(int page) {
        return OkGo.<HttpData<MyAddressBean>>get(HttpConfig.BASE_URL + HttpConfig.MARKET_GET_MY_ADDRESS)
                .params("page", page + "");
    }

    //删除地址
    public PostRequest<HttpData> onDeleteAddress(int id) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.MARKET_DELETE_MY_ADDRESS)
                .params("id", id);
    }

    //设置默认地址
    public PostRequest<HttpData> setDetailAddress(int id) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.MARKET_SET_DETAILS_ADDRESS)
                .params("id", id);
    }

    /**
     * 获取收获地址信息
     *
     * @param id ID
     * @return
     */
    public GetRequest<HttpData<AddressBean>> getAddressData(int id) {
        return OkGo.<HttpData<AddressBean>>get(HttpConfig.BASE_URL + HttpConfig.MARKET_GET_ADDRESS_DATA)
                .params("address_id", id);
    }

    /**
     * 获取分类信息
     *
     * @param id
     * @return
     */
    public GetRequest<HttpData<GoodCategoryBean>> getGoodCategoryData(int page,int id) {
        return OkGo.<HttpData<GoodCategoryBean>>get(HttpConfig.BASE_URL + HttpConfig.MARKET_GET_GOOD_CATEGORY_DATA)
                .params("page", page)
                .params("category_id", id);
    }

    /**
     * 商城搜索
     *
     * @param key_words 要搜索的数据
     * @return
     */
    public GetRequest<HttpData<ShopSearchBean>> getSearchData(String page,String key_words,int category_id) {
        return OkGo.<HttpData<ShopSearchBean>>get(HttpConfig.BASE_URL + HttpConfig.MARKET_SHOP_SEARCH)
                .params("page", page)
                .params("key_words", key_words)
                .params("category_id", category_id);
    }

    /**
     * 商品详情
     *
     * @param id 商品ID
     * @return
     */
    public GetRequest<HttpData<ShopDetailsBean>> getShopDetails(int id) {
        return OkGo.<HttpData<ShopDetailsBean>>get(HttpConfig.BASE_URL + HttpConfig.MARKET_GET_SHOP_DETAILS)
                .params("product_id", id);
    }

    //编辑收货地址
    public PostRequest<HttpData> addEditorAddress(int id, String name, String phone, String province, String city, String region, String detail, String is_default) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.MARKET_EDITOR_ADDRESS)
                .params("id", id)
                .params("name", name)
                .params("phone", phone)
                .params("province", province)
                .params("city", city)
                .params("country", region)
                .params("detail", detail)
                .params("is_default", is_default);
    }

    /**
     * @return 返回默认地址数据
     */
    public GetRequest<DefaultAddressBean> getDefaultAddress() {
        return OkGo.<DefaultAddressBean>get(HttpConfig.MARKET_DEFAULT_ADDRESS);
    }


    /**
     * @param productId 商品id
     * @param areaId    地区id
     * @param count     购买数量
     * @param remarks   备注
     * @return 返回订单生成情况
     */
    public PostRequest<CreateOrderBean> createOrder(String productId, String areaId, String count, String remarks) {
        return OkGo.<CreateOrderBean>post(HttpConfig.MARKET_ORDER_CREATE)
                .params("product_id", productId)
                .params("address_id", areaId)
                .params("num", count)
                .params("remark", remarks);
    }

    /**
     * @param orderId 订单id
     * @return 返回订单详情
     */
    public GetRequest<OrderDetailsBean> orderDetails(String orderId) {
        return OkGo.<OrderDetailsBean>get(HttpConfig.MARKET_ORDER_DETAILS)
                .params("order_id", orderId);
    }

    /**
     * @param page 当前页数
     * @return 返回全部订单列表
     */
    public GetRequest<HttpData<PageBean<OrderListBean>>> getOrderList(String page) {
        return OkGo.<HttpData<PageBean<OrderListBean>>>get(HttpConfig.MARKET_ALL_ORDER)
                .params("page", page);
    }

    public GetRequest<HttpData<PageBean<OrderListBean>>> getStatusList(String page, String status) {
        return OkGo.<HttpData<PageBean<OrderListBean>>>get(HttpConfig.MARKET_ORDER_STATUS)
                .params("page", page)
                .params("status", status);
    }


    /**
     * @param sn  订单号
     * @param pwd 密码
     * @return 支付成功结果
     */
    public PostRequest<HttpData> orderPay(String sn, String pwd) {
        return OkGo.<HttpData>post(HttpConfig.MARKET_ORDER_PAY)
                .params("sn", sn)
                .params("payment_password", pwd);
    }

    /**
     * @param orderId 订单id
     * @return 返回确认收货结果
     */
    public PostRequest<HttpData> orderEnsure(String orderId) {
        return OkGo.<HttpData>post(HttpConfig.MARKET_ORDER_ENAURE)
                .params("order_id", orderId);
    }

    /**
     * @param orderId 订单id
     * @return 返回取消订单结果
     */
    public PostRequest<HttpData> orderCancel(String orderId) {
        return OkGo.<HttpData>post(HttpConfig.MARKET_ORDER_CANCEL)
                .params("order_id", orderId);
    }

    /**
     * @param orderId 订单id
     * @return 返回删除订单结果
     */
    public PostRequest<HttpData> orderDelete(String orderId) {
        return OkGo.<HttpData>post(HttpConfig.MARKET_ORDER_DELETE)
                .params("order_id", orderId);
    }

    public GetRequest<ServicesBean> getKefu() {
        return OkGo.<ServicesBean>get(HttpConfig.MARKET_SERVICES);
    }
}
